< previous page page_299 next page >

Page 299
z0319-01.gif
Figure 10.20
Level one, two, and three Sierpinski curves.
of this in another way, if you want a depth N Hilbert curve to have width and height W, make the line segments W / (2N 1) long.
Finally, Hilbert curves are square with their starting and ending positions located in two adjacent corners. Together, these features make it easy to design borders, dividers, and other decorations using Hilbert curves. Figure 10.19 shows a box made from 12 level-three Hilbert curves connected by short line segments.
Sierpinski Curves
Sierpinski curves are also self-similar curves that are naturally defined recursively. Figure 10.20 shows Sierpinski curves of levels one, two, and three.
The Hilbert curve subroutine in the previous section calls itself recursively to draw Hilbert curves. Sierpinski curves are easier to draw with four routines working together than with a single routine. These four routines are named SierpA, SierpB, SierpC, and SierpD. The routines are indirectly recursive. Each routine calls the others, which may later call the first. The different routines draw the top, left, bottom, and right parts of a Sierpinski curve. In Figure 10.21, these parts of the curve are labeled A, B, C, and D so that you can see which routine draws the different parts of the curve.
Each of the four curve types is composed of a diagonal line segment, a vertical or horizontal line segment, and another diagonal line segment. When the depth of recursion is greater than 1, the program breaks each curve's two diagonal line segments into two smaller curves. For example, to break up a type A curve, the program breaks the first diagonal segment into a type A curve followed by a type B curve. Next, the program draws a horizontal line segment. It then breaks the second diagonal segment into a type D curve followed by a type A curve.
z0319-02.gif
Figure 10.21
The four basic types of
Sierpinski subcurves.

 
< previous page page_299 next page >